<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:MaterialsInvoicingSummary:Export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="BillingList" border class="table">
      <el-table-column prop="index" label="序号" width="55" align="center"></el-table-column>
      <el-table-column label="开票时间" prop="invoiceTime" align="center">
      </el-table-column>
      <el-table-column label="供应商" prop="provide" align="center">
      </el-table-column>
      <el-table-column prop="provideWare" label="仓库" width="180" align="center">
        <template slot-scope="scope">
            <div v-if="scope.row.provideWare==='中心库'" class="DataCenter">
            <el-image :src="zxkImg" class="zxkImg"></el-image>
            <span class="text">{{ scope.row.provideWare }}</span>
          </div>
          <div v-if="scope.row.provideWare==='配件库'" class="DataCenter">
            <span class="text1">{{ scope.row.provideWare }}</span>
          </div>

        </template>
      </el-table-column>
      <el-table-column prop="provideType" label="类型" width="180" align="center">
      </el-table-column>
      <el-table-column prop="provideGroup" label="种类" width="180" align="center">
        <template slot-scope="scope">
            <div v-if="scope.row.provideGroup==='配件'" class="DataCenter">
            <el-image :src="pjImg" class="zxkImg"></el-image>
            <span class="text1">{{ scope.row.provideGroup }}</span>
          </div>
          <div v-if="scope.row.provideGroup==='轮胎'" class="DataCenter">
            <el-image :src="ltImg" class="pjkImg"></el-image>
            <span class="text1">{{ scope.row.provideGroup }}</span>
          </div>
          <div v-if="scope.row.provideGroup==='制冷剂'" class="DataCenter">
            <el-image :src="zljImg" class="zxkImg"></el-image>
            <span class="text1">{{ scope.row.provideGroup }}</span>
          </div>
          <div v-if="scope.row.provideGroup==='润滑油'" class="DataCenter">
            <el-image :src="yhyImg" class="pjkImg"></el-image>
            <span class="text1">{{ scope.row.provideGroup }}</span>
          </div>
          </template>
      </el-table-column>
      <el-table-column prop="provideMoney" label="金额 (元) " align="center">
        <template slot-scope="scope">
          <span style="float: right;">{{ formatNumber(parseFloat(scope.row.provideMoney).toFixed(2)) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="balanceMoney" label="余额 (元) " align="center">
        <template slot-scope="scope">
          <span style="float: right;">{{ formatNumber(parseFloat(scope.row.balanceMoney).toFixed(2)) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.provideType === '开票'">开票编码:{{ scope.row.remark }}  ({{ scope.row.provideWare }}{{ scope.row.provideGroup }})</span>
          <span v-if="scope.row.provideType === '作废'">开票编码:{{ scope.row.remark }}  ({{ scope.row.provideWare }}{{ scope.row.provideGroup }})-{{scope.row.provideType}}</span>
          <span v-if="scope.row.provideType === '入账'">{{ scope.row.remark }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" layout="total, sizes, prev, pager, next, jumper" :total="total"
      :page.sync="queryParams.pageNum" @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

  </div>
</template>

<script>
import { detailList } from "@/api/system/supplierBillingDetail";
export default {
  name: "WarehouseDetail",
  data() {
    return {
      zxkImg: require('../../../assets/icon/zxk.png'),
      pjImg: require('../../../assets/icon/pj.png'),
      ltImg: require('../../../assets/icon/lt.png'),
      zljImg: require('../../../assets/icon/zlj.png'),
      yhyImg: require('../../../assets/icon/yhy.png'),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商付款表格数据
      BillingList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        provide: "",
        provideGroup: "",
        provideWare: "",
        company:""
      },
      deptName: "",
      fisrtActivate: true
    };
  },
  created() {
    this.eventHnadling();
  },
  activated() {
    if (!this.fisrtActivate) {
      this.eventHnadling();
    } else {
      // 防止 重复请求
      this.fisrtActivate = false;
    }
  },
  methods: {

    eventHnadling() {
      const User = localStorage.getItem('User');
      this.deptName = JSON.parse(User).dept ? JSON.parse(User).dept.deptName : '';
      if (this.deptName !== '物资公司') {
        this.queryParams.provide = this.deptName;
      } else {
        this.queryParams.provide = this.$route.query.provide;
      }
      this.getList();
    },
    /** 查询供应商付款列表 */
    getList() {
      this.loading = true;
      this.queryParams.provideGroup = this.$route.query.productGroup;
      this.queryParams.provideWare = this.$route.query.productWare;
      this.queryParams.company = this.$route.query.company
      detailList(this.queryParams).then(response => {
        if (response.code === 200) {
          this.BillingList = response.data.list;
          this.BillingList.forEach((item, index) => {
            item.index = (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
          })
          this.total = response.data.total

        }
        this.loading = false;
      });
    },


    // 表单重置

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.provide = "";
      this.handleQuery();
    },

    // 分页
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
    },


    /** 导出按钮操作 */
    handleExport() {
      // this.download('system/provideRecords/exportProvideWare', {
      //   ...this.queryParams
      // }, `仓库明细${this.queryParams.createTime}.xlsx`)
    },
    // 数字转换
    formatNumber(value) {
      if (value) {
        let [integerPart, decimalPart] = value.toString().split('.');
        let formattedNumber = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',') + '.' + decimalPart.slice(0, 3);
        return formattedNumber;
      }

    }
  }
};
</script>
<style lang="scss" scoped>
.textNum {
  float: right;
  color: red;
}

.textNum:hover {
  color: #409EFF;
}

.table {
  .el-table__body-wrapper {
    // height: 650px !important;
    overflow-y: auto !important;
  }
}
.zxkImg{
  width: 30px;
  height: 30px;
}
.DataCenter{
  display: flex;
    justify-content: center;
    align-items: center;
}
.text{
  margin-top: 10px;
}
.pjkImg{
  width: 28px;
  height: 28px;
}
.text1{
  margin-top: 2px;
  margin-left: 5px;
}
</style>
